package com.igeek.javase.ch05.hashmaps;

/*
 *@author wangpeng
 *2023/7/17 18:02
 *@description TODO
 */
/**
 * 功能需求：
 *HashMap<User,String>
 * 封装 add(User元素)  添加User时，姓名和密码一致则判定是同一元素，将不予以添加
 */
public class User {
    private String name;
    private String password;

    public User(String name, String password) {
        this.name = name;
        this.password = password;
    }

    // 重写hashCode和equals方法
    @Override
    public int hashCode() {
        return name.hashCode() + password.hashCode();
    }

    @Override
    public boolean equals(Object obj) {
        if (this == obj) {
            return true;
        }
        if (obj == null || getClass() != obj.getClass()) {
            return false;
        }
        User user = (User) obj;
        return name.equals(user.name) && password.equals(user.password);
    }
    public String getName(){
        return name;
    }
    public String getPassword(){
        return password;
    }
}
